home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM 1
/
LIGHT-ROM 1 (Amiga Library Services)(1994).iso
/
ffdisks
/
d998.lha
/
TeXPrt
/
source
/
TeXPrt.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-05
|
20KB
|
457 lines
/***************************************************************************
* *
* Filename : TeXPrt.c *
* *
* Description : A front-end for DVI printer driver. *
* *
* Return Codes : 0 - Program finished without errors. *
* 1 - Error abort. *
* *
***************************************************************************
* *
* Modification History *
* *
* Date Author Comments *
* ---------------------------------------------------------------------- *
* 3.3.92 R.Bödi Created. *
* 5.3.92 R.Bödi Added Printout-requester and config file. *
* 29.6.92 R.Bödi Added 'No of Copies' string gadget. *
* Changed log shell. *
* 24.9.92 R.Bödi Added ability to use the DVILJ2P printer driver *
* as an alternative to the PasTeX DVIPrint. *
* Disadvantage : No metafont call if a font is *
* not available. *
* 25.9.92 R.Bödi Added AREXX-Port. *
* 24.10.92 R.Bödi Few changes for SAS/C 6.0 *
* 25.10.92 R.Bödi Now fetches the actual filename of the DVI file *
* from the ShowDVI previewer if possible. This *
* needs the ARexx script file TeXPrtPrint.tpr to *
* work. *
* 28.10.92 R.Bödi Added NOREQ option to the AREXX print command *
* which suppresses the confirmation requester. *
* 22.5.93 R.Bödi Now multiple TeX printer driver are supported *
* via driver description files (ASCII). *
* 19.6.93 R.Bödi Added Boopsi gadget for calling file requester. *
* Thanks to Jan van den Baard for supporting it. *
* Added AppIcon and AppWindow. *
* 2.11.93 R.Bödi Changed structure TeXDriver, see TeXPrt.h *
* 12.2.94 R.Bödi Turned TeXPrt into a MUI application. *
* *
***************************************************************************
* *
* Copyright © 1992-1994 Richard Bödi, All rights reserved. *
* *
***************************************************************************/
/*----------------------------- INCLUDES ----------------------------------*/
#include "TeXPrt.h"
#include "TexPrt_protos.h"
#include "TexPrt_globals.h"
/*-------------------------- GLOBAL DATA ----------------------------------*/
char AppName[] = "TeXPrt";
char Version[] = "$VER: TeXPrt"VERSION""__AMIGADATE__;
char Title[] = "TeXPrint";
char TempFileName[] = "t:TeXPrint.tmp";
char DefaultShell[] = "newshell CON:0/0/640/150/TeXPrint-Output";
char DriverDrawer[] = "TeXDrivers";
char DriverLogo[] = "TeXPrt printer driver spec file";
char TeXPrintEnv[] = "TeXPrint";
char RexxPrintMacro[] = "run sys:Rexxc/rx TexPrtPrint.tpr";
char RexxStartupMacro[] = "run sys:Rexxc/rx TexPrtInit.tpr";
struct Args Args;
struct AvailDrivers Drivers;
struct TeXDriver TeXDriver;
struct RawSettings RawSettings;
struct ParsedSettings ParsedSettings;
struct DefaultSettings DefaultSettings;
struct MUIPointers MUIPointers;
struct StructPointers StructPointers;
USHORT ActualDriver;
ULONG IDCMPFlag = 0;
struct MsgPort *AppMsgPort = NULL;
struct DiskObject *AppIconObj = NULL;
struct AppIcon *AppIcon = NULL;
struct Library *MUIMasterBase = NULL;
struct NewMenu *Menu = NULL;
struct EasyStruct
ConfirmReq = { sizeof (struct EasyStruct), 0, (UBYTE *)"Confirm Printout",
(UBYTE *)"\n Start Printing ? \n\n Printer : %s \n \n Print %s \n",
(UBYTE *)"Confirm|Cancel" },
AboutReq = { sizeof (struct EasyStruct), 0, (UBYTE *)"About",
(UBYTE *)"\n %s \n\n A front end for the DVI printer driver \n\n\
(c) 1993-1994 by Richard Bödi\n\n\
Mathematisches Institut\n\
Universität Tübingen\n\
Auf der Morgenstelle 10\n\
72076 Tübingen\n\
Germany\n\n\
e-mail :\n\
mmisa01@mailserv.zdv.uni-tuebingen.de\n",
(UBYTE *)"OK" },
AppIconReq = { sizeof (struct EasyStruct), 0, (UBYTE *)"About",
(UBYTE *)"\n This is the AppIcon of the TeXPrt program.\
\n To select a DVI-File for printing, \n\
simply drag its icon over this one. \n",
(UBYTE *)"Fine|Quit TeXPrt" },
LoadErrorReq = { sizeof (struct EasyStruct), 0, (UBYTE *)"Load Error",
(UBYTE *)"\n Error in TeXDriver specification file \n %s\n Last line read: %ld\n",
(UBYTE *)"Accept" },
SaveErrorReq = { sizeof (struct EasyStruct), 0, (UBYTE *)"Save Error",
(UBYTE *)"\n Couldn't save TeXDriver specification file \n\n %s \n",
(UBYTE *)"Accept" },
NoDVIFileReq = { sizeof (struct EasyStruct), 0, (UBYTE *)"No DVI file specified",
(UBYTE *)"\n Please select a DVI file to print.\n", (UBYTE *)"of course" },
QuitReq = { sizeof (struct EasyStruct), 0, (UBYTE *)"Quit Program",
(UBYTE *)"\n Really quit the program ?\n", (UBYTE *)"Yes|No" };
/*------------------------------- CODE ------------------------------------*/
main (int argc, char *argv[])
{
int Error = 1;
USHORT Line;
long Signals = 0;
char RexxPortName[NAMELENGTH];
BPTR OldDirectory, OwnDirectory;
struct MsgPort *PortFound;
OwnDirectory = GetProgramDir ();
OldDirectory = CurrentDir (OwnDirectory);
stpcpy (RexxPortName, AppName);
strupr (RexxPortName);
strcat (RexxPortName, ".1");
Forbid ();
PortFound = FindPort (RexxPortName);
Permit ();
if (!PortFound)
{
stpcpy (Args.ArgStr[KW_SHELL], DefaultShell);
if (argc == 0)
ParseWB ((struct WBStartup *)argv);
if (argc > 1)
ParseShell (argc, argv);
if (OpenLibs ())
printf ("Error opening library.\n");
else
{
Drivers.NoOfDrivers = ScanDrivers (&Drivers);
if (Drivers.NoOfDrivers <= 0)
{
if (Drivers.NoOfDrivers == 0)
printf ("No TeX printer drivers found in drawer %s.\n", DriverDrawer);
else
printf ("DOS error or no memory for pattern matching. \n");
}
else
{
if (!(Menu = BuildMenuStructure (&Drivers, &ActualDriver)))
printf ("Couldn't build up menu.\n");
else
{
if (!BuildMUIApp (&MUIPointers, Menu))
printf ("Couldn't create MUI application.\n");
else
{
StructPointers.AvailDrivers = &Drivers;
StructPointers.TeXDriver = &TeXDriver;
StructPointers.RawSettings = &RawSettings;
StructPointers.ParsedSettings = &ParsedSettings;
StructPointers.DefaultSettings = &DefaultSettings;
StructPointers.DriverNumber = ActualDriver;
StructPointers.MUIPointers = &MUIPointers;
if (Line = LoadDriverSpec (&StructPointers, ActualDriver))
EasyRequest (MUIPointers.MainWindow, &LoadErrorReq, &IDCMPFlag,
Drivers.DriverFiles + ActualDriver * NAMELENGTH, Line);
else
UpdateGUI (&MUIPointers, &DefaultSettings, &ParsedSettings);
SetAttrs (MUIPointers.STR_DVIFile, MUIA_String_Contents, Args.ArgStr[KW_FILE], TAG_DONE);
Forbid ();
PortFound = FindPort (RexxPortName);
Permit ();
if (PortFound) StructPointers.ARexxAvailable = TRUE;
else StructPointers.ARexxAvailable = FALSE;
if (Args.ArgStr[KW_APPICON][0])
if (BuildAppIcon (&AppMsgPort, &AppIconObj, &AppIcon, Args.ArgStr[KW_APPICON]))
Signals = 1L<<AppMsgPort->mp_SigBit;
ProcessIDCMP (&StructPointers, Signals);
Error = 0;
}
}
}
}
}
else
system (RexxStartupMacro);
CurrentDir (OldDirectory);
Cleanup ();
return (0);
}
/***************************************************************************
* *
* Function name : CallPrinterDriver *
* *
* Description : Creates the parameter list for the printer driver and *
* calls the appropriate printer driver. *
* *
***************************************************************************
* *
* Synopsis : CallPrinterDriver (Pointers, NoReq) *
* *
* Parameters : *
* (struct Structures *) Pointers: *
* A structure consisting of APTRs to various data structures. *
* (BOOL) NoReq : *
* TRUE, if a confirmation requester should appear, *
* FALSE, otherwise *
* *
* Return value : None *
* *
***************************************************************************/
void CallPrinterDriver (struct StructPointers *Pointers, BOOL NoReq)
{
int OptionCount, Cnt;
ULONG GetInt, From, To, Copies;
char *DVIFile;
char PrinterName[NAMELENGTH], Pages[NAMELENGTH],
Command[CMDSTRLENGTH], TempBuffer[CMDLENGTH], Console[CMDSTRLENGTH];
BOOL Print;
FILE *TmpFp;
set (Pointers->MUIPointers->app, MUIA_Application_Sleep, TRUE);
GetAttr (MUIA_String_Integer, Pointers->MUIPointers->STR_From, &From);
GetAttr (MUIA_String_Integer, Pointers->MUIPointers->STR_To, &To);
if (GetVar ("DVIPrint", PrinterName, sizeof (PrinterName), GVF_GLOBAL_ONLY) == -1)
stpcpy (PrinterName, "printer=generic");
GetAttr (MUIA_Radio_Active, Pointers->MUIPointers->RAD_FromTo, &GetInt);
if (GetInt == DOCUMENT)
stpcpy (Pages, "whole document");
else
if (From == To) sprintf (Pages, "page %d", From);
else sprintf (Pages, "pages %d to %d", From, To);
GetAttr (MUIA_Radio_Active, Pointers->MUIPointers->RAD_OddEven, &GetInt);
if (GetInt == ODD) strcat (Pages, " (odd pages)");
if (GetInt == EVEN) strcat (Pages, " (even pages)");
if (NoReq) Print = TRUE;
else Print = EasyRequest (Pointers->MUIPointers->MainWindow, &ConfirmReq, &IDCMPFlag, &PrinterName[8], Pages);
GetAttr (MUIA_String_Contents, Pointers->MUIPointers->STR_DVIFile, &GetInt);
DVIFile = (char *)GetInt;
if ((strlen (DVIFile) == 0) && Print)
{
EasyRequest (Pointers->MUIPointers->MainWindow, &NoDVIFileReq, &IDCMPFlag, NULL);
Print = FALSE;
}
if (Print)
{
stpcpy (Command, Pointers->TeXDriver->ProgramNode);
strcat (Command, Pointers->ParsedSettings->Misc);
GetAttr (MUIA_Radio_Active, Pointers->MUIPointers->RAD_FromTo, &GetInt);
if (GetInt == FROMTO)
{
sprintf (TempBuffer, " %s%d", Pointers->ParsedSettings->From, From);
strcat (Command, TempBuffer);
if (strcmp (Pointers->ParsedSettings->To, " "))
sprintf (TempBuffer, " %s%d", Pointers->ParsedSettings->To, To);
else
sprintf (TempBuffer, " %s%d", Pointers->ParsedSettings->NoOfPages, To - From + 1);
strcat (Command, TempBuffer);
}
if (strcmp(Pointers->ParsedSettings->Copies, " "))
{
GetAttr (MUIA_String_Integer, Pointers->MUIPointers->STR_Copies, &Copies);
sprintf (TempBuffer, " %s%d", Pointers->ParsedSettings->Copies, Copies);
strcat (Command, TempBuffer);
}
GetAttr (MUIA_Radio_Active, Pointers->MUIPointers->RAD_OddEven, &GetInt);
switch (GetInt)
{
case ALL:
sprintf (TempBuffer, " %s", Pointers->ParsedSettings->AllPages);
break;
case ODD:
sprintf (TempBuffer, " %s", Pointers->ParsedSettings->OddPages);
break;
case EVEN:
sprintf (TempBuffer, " %s", Pointers->ParsedSettings->EvenPages);
break;
}
strcat (Command, TempBuffer);
GetAttr (MUIA_Radio_Active, Pointers->MUIPointers->RAD_Orientation, &GetInt);
if (GetInt == PORTRAIT)
sprintf (TempBuffer, " %s", Pointers->ParsedSettings->Portrait);
else
sprintf (TempBuffer, " %s", Pointers->ParsedSettings->LandScape);
strcat (Command, TempBuffer);
if (strcmp(Pointers->ParsedSettings->HOffset, " "))
{
GetAttr (MUIA_String_Integer, Pointers->MUIPointers->STR_X, &GetInt);
sprintf (TempBuffer, " %s%d%s", Pointers->ParsedSettings->HOffset,
GetInt + Pointers->DefaultSettings->AdjHOffset,
Pointers->ParsedSettings->HOffsetUnit);
strcat (Command, TempBuffer);
}
if (strcmp(Pointers->ParsedSettings->VOffset, " "))
{
GetAttr (MUIA_String_Integer, Pointers->MUIPointers->STR_Y, &GetInt);
sprintf (TempBuffer, " %s%d%s", Pointers->ParsedSettings->VOffset,
GetInt + Pointers->DefaultSettings->AdjVOffset,
Pointers->ParsedSettings->VOffsetUnit);
strcat (Command, TempBuffer);
}
for (OptionCount = 0; OptionCount < OPTIONS; OptionCount++)
{
GetAttr (MUIA_Selected, Pointers->MUIPointers->CHM_Option[OptionCount], &GetInt);
if (GetInt)
{
sprintf (TempBuffer, " %s", Pointers->ParsedSettings->Option[OptionCount]);
strcat (Command, TempBuffer);
}
}
GetAttr (MUIA_String_Contents, Pointers->MUIPointers->STR_OutFile, &GetInt);
sprintf (TempBuffer, " %s%s ", Pointers->ParsedSettings->Device, GetInt);
strcat (Command, TempBuffer);
strcat (Command, Pointers->ParsedSettings->DVIFile);
strcat (Command, DVIFile);
if (TmpFp = fopen (TempFileName, "w"))
{
fprintf (TmpFp, "failat 999\n");
fprintf (TmpFp, "stack 50000\n");
if (strcmp (Pointers->ParsedSettings->Copies, " ")) Copies = 1;
for (Cnt = 0; Cnt < Copies; Cnt++) fprintf (TmpFp, "%s\n", Command);
fprintf (TmpFp, "Wait 5\n");
fprintf (TmpFp, "endcli\n");
fclose (TmpFp);
Delay (10);
stpcpy (Console, Args.ArgStr[KW_SHELL]);
strcat (Console, " from ");
strcat (Console, TempFileName);
system (Console);
}
}
set (Pointers->MUIPointers->app, MUIA_Application_Sleep, FALSE);
}
/***************************************************************************
* *
* Function name : OpenLibs *
* *
* Description : Opens the following libraries: *
* muimaster.library *
* *
***************************************************************************
* *
* Synopsis : OpenLibs () *
* *
* Parameters : None *
* *
* Return value : (int) *
* 0, if opening of all libraries succeeded. *
* >0, if a library couldn't be openend. *
* *
***************************************************************************/
int OpenLibs (void);
int OpenLibs ()
{
int Error = 0;
if (!(MUIMasterBase = OpenLibrary((UBYTE *)MUIMASTER_NAME, (ULONG)MUIMASTER_VMIN)))
Error++;
return (Error);
}
/***************************************************************************
* *
* Function name : Cleanup *
* *
* Description : Frees all allocated memory, closes all used libraries, *
* closes all screens and windows. *
* *
* *
***************************************************************************
* *
* Synopsis : Cleanup () *
* *
* Parameters : None *
* *
* Return value : None *
* *
***************************************************************************
* *
* Copyright © 1992 Richard Bödi, All rights reserved. * *
* *
***************************************************************************/
void Cleanup ()
{
DeleteFile (TempFileName);
if (AppIconObj) FreeDiskObject (AppIconObj);
if (AppIcon) RemoveAppIcon (AppIcon);
if (AppMsgPort) DeleteMsgPort (AppMsgPort);
if (MUIPointers.app) MUI_DisposeObject (MUIPointers.app);
if (Menu) free (Menu);
if (MUIMasterBase) CloseLibrary (MUIMasterBase);
}
/*---------------------------- END OF FILE --------------------------------*/